﻿Imports Persistencia
Imports System.IO

Public Class frmPrincipal

#Region "Métodos"

    Public Function verificarConexao() As Boolean

        Dim objAcesso As New PersistenciaPadrao.AcessoBD

        Dim bConexaoRealizada As Boolean = False
        Dim bTesteConexao As Boolean = False
        Dim sStringConexao As String = ""

        sStringConexao = PersistenciaPadrao.Uteis.lerArquivoConexao

        bTesteConexao = objAcesso.testarConexao(sStringConexao)

        If Not bTesteConexao Then
            Dim frmConexao As New FronteiraPadrao.frmConexaoBD
            frmConexao.ShowDialog()
            bConexaoRealizada = frmConexao.conexaoRealizada
            sStringConexao = PersistenciaPadrao.Uteis.lerArquivoConexao
        Else
            bConexaoRealizada = True
        End If

        Persistencia.AcessoBD.StringConexao = sStringConexao

        Return bConexaoRealizada

    End Function

#End Region

#Region "Eventos"

    Private Sub TiposPontoDeAtendimentoToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TiposPontoDeAtendimentoToolStripMenuItem.Click
        Dim frm As New frmTipoPA
        frm.MdiParent = Me
        frm.Show()
    End Sub

    Private Sub SairToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SairToolStripMenuItem.Click
        Application.Exit()
    End Sub

    Private Sub frmPrincipal_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load


        Try
            Persistencia.AcessoBD.CodSGBD = PersistenciaPadrao.AcessoBD.eSGBD.MY_SQL
            PersistenciaPadrao.AcessoBD.codSGBD = PersistenciaPadrao.AcessoBD.eSGBD.MY_SQL
            PersistenciaPadrao.AcessoBD.sCaminhoAplicacao = Application.StartupPath

            Me.verificarConexao()

        Catch ex As Exception
            MsgBox("Ocorreu um erro ao iniciar o sistema. " & ex.Message, MsgBoxStyle.Critical, Me.Text)
        End Try

    End Sub

    Private Sub PontosDeAtendimentoToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PontosDeAtendimentoToolStripMenuItem.Click
        Dim frm As New frmPontoAtendimento
        frm.MdiParent = Me
        frm.Show()
    End Sub

#End Region

End Class